<?php
class DataUtil{

	const VALUE_YES='1';
	const VALUE_NO='0';
	
	const VALUE_MALE='1';
	const VALUE_FEMALE='0';
	

	/**
	 * Convenient method to get string representation - Yes/No - of 1/0;
	 * OR return array for selection.
	 * @param mixed $val selected value; if null, then return array.
	 * @param boolean $empty whether include empty options.
	 * @return Ambigous <string>|multitype:string Yes or No if $val is specified; OR array if not.
	 */
	public static function getOptionYesNo($val=NULL, $empty=FALSE){
		$options = $empty ? array(''=>'',self::VALUE_YES=>'Yes',self::VALUE_NO=>'No'):
									array(self::VALUE_YES=>'Yes',self::VALUE_NO=>'No');
		if($val != null){
			return $options[$val];
		}
		return $options;
	}

	/**
	 * Get array of Australian States.
	 * @return array,  array['NSW']='NSW'
	 */
	public static function getStates(){
		return array(
			'NSW'=>'NSW',
			'ACT'=>'ACT',
			'VIC'=>'VIC',
			'QLD'=>'QLD',
			'SA'=>'SA',
			'WA'=>'WA',
			'TAS'=>'TAS',
			'NT'=>'NT',
		);
	}




	/*
	 '2LT'=>'2LT',
	 'AB'=>'AB',
	 'AC'=>'AC',
	 'ACW'=>'ACW',
	 'APP'=>'APP',
	 'AS'=>'AS',
	 'BDR'=>'BDR',
	 'BRIG'=>'BRIG',
	 'CAPT'=>'CAPT',
	 'CFN'=>'CFN',
	 'CHAP'=>'CHAP',
	 'CHAPGEN'=>'CHAPGEN',
	 'CMDR'=>'CMDR',
	 'COL'=>'COL',
	 'CPL'=>'CPL',
	 'CPO'=>'CPO',
	 'FLGOFF'=>'FLGOFF',
	 'FLTLT'=>'FLTLT',
	 'FM'=>'FM',
	 'FSGT'=>'FSGT',
	 'GEN'=>'GEN',
	 'GNR'=>'GNR',
	 'LAC'=>'LAC',
	 'LACW'=>'LACW',
	 'LBDR'=>'LBDR',
	 'LCDR'=>'LCDR',
	 'LCPL'=>'LCPL',
	 'LS'=>'LS',
	 'LT'=>'LT',
	 'LTCOL'=>'LTCOL',
	 'MAJ'=>'MAJ',
	 'MAJGEN'=>'MAJGEN',
	 'MO'=>'MO',
	 'MUSN'=>'MUSN',
	 'OCDT'=>'OCDT',
	 'OFFCDT'=>'OFFCDT',
	 'PLTOFF'=>'PLTOFF',
	 'Prof'=>'Prof',
	 'PTE'=>'PTE',
	 'PTE(T)'=>'PTE(T)',
	 'REC'=>'REC',
	 'Rev'=>'Rev',
	 'SCDT'=>'SCDT',
	 'SCHAP (JEW)'=>'SCHAP (JEW)',
	 'SGT'=>'SGT',
	 'SIG'=>'SIG',
	 'SMN'=>'SMN',
	 'SPR'=>'SPR',
	 'SQNLDR'=>'SQNLDR',
	 'SSGT'=>'SSGT',
	 'TPR'=>'TPR',
	 'WO'=>'WO',
	 'WO1'=>'WO1',
	 'WO2'=>'WO2',
	 */
	/**
	 * Get array of personal titles.
	 * @return array of string array['Mr']='Mr'
	 */
	public static function getTitles(){
		return array(
			'Mr'=>'Mr',
			'Ms'=>'Ms',
			'Miss'=>'Miss',
			'Mrs'=>'Mrs',
			'Sir'=>'Sir',
	 		'Lady'=>'Lady',
	 		'Dr'=>'Dr',
	 		'Master'=>'Master',
	 		'Sr'=>'Sr',
		);
	}
	
	public static function getNumers($max){
		$results=array();
		for ($i = 0; $i <=$max; $i++) {
			$results[$i]=$i;
		}
		return $results;
	}
	
	public static function getGenders(){
		return array(self::VALUE_FEMALE=>"Female",self::VALUE_MALE=>"Male");
	}
	public static function getGender($code){
		return $code==self::VALUE_MALE?"Male":"Female";
	}
	
	public static function rrmdir($dir) {
		if (!is_dir($dir))
			return false;
		
		$objects = scandir($dir);
		foreach ($objects as $object) { 
			if ($object != "." && $object != "..") { 
				if (filetype($dir."/".$object) == "dir") 
					self::rrmdir($dir."/".$object); 
				else 
					@unlink($dir."/".$object);
			} 
		} 
		@rmdir($dir);
		return true;
	}
}